/**
 * 
 *  @project Air Traff Monitor
 * 
 *  @author M.Emre ATASEVER <m.emre.atas@gmail.com>
 *  @author M.Burak ALKAN <mburakalkan@gmail.com>
 *  @author H.Burak KARAMIK <bkaramik@gmail.com>
 *
 *	`Air Traffic Monitor' is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


#ifndef  KISMODEL_INC
#define  KISMODEL_INC

#include "kisock.h"
#include <QAbstractItemModel>

class KismetItemModel : public QAbstractItemModel
{
public:
	virtual void clear() = 0;
};

template<typename Root, typename Item>class KismetDataModel : public KismetItemModel
{
public:
	KismetDataModel(QKismetSocket *sock)
	{
		socket		= sock;	
		rootItem	= new Root();
	}
	~KismetDataModel()
	{
		qDeleteAll(rootItem->items);
		delete rootItem;
	}
	
	int rowCount(const QModelIndex &parent = QModelIndex()) const
	{
		if(!parent.isValid())
			return rootItem->items.size();
		else return 0;
	}

	void clear()
	{
		beginRemoveRows(QModelIndex(),0,rowCount()-1);
		qDeleteAll(rootItem->items);
		rootItem->items.clear();
		endRemoveRows();
	}
protected:
	QKismetSocket *socket;
	Root *rootItem;
};

#endif 
